﻿package morn.core.components
{
    import flash.events.*;
    import flash.filters.*;
    import flash.text.*;
    import morn.core.utils.*;

    public class Label extends Component
    {
        protected var _textField:TextField;
        protected var _format:TextFormat;
        protected var _text:String = "";
        protected var _isHtml:Boolean;
        protected var _stroke:String;
        protected var _skin:String;
        protected var _margin:Array;

        public function Label(param1:String = "", param2:String = null)
        {
            this._margin = [0, 0, 0, 0];
            this.text = param1;
            this.skin = param2;
            return;
        }// end function

        override protected function preinitialize() : void
        {
            mouseEnabled = false;
            mouseChildren = true;
            return;
        }// end function

        override protected function createChildren() : void
        {
            var _loc_1:* = new TextField();
            this._textField = new TextField();
            addChild(_loc_1);
            return;
        }// end function

        override protected function initialize() : void
        {
            this._format = this._textField.defaultTextFormat;
            this._format.font = Styles.fontName;
            this._format.size = Styles.fontSize;
            this._format.color = Styles.labelColor;
            this._textField.selectable = false;
            this._textField.autoSize = TextFieldAutoSize.LEFT;
            this._textField.embedFonts = Styles.embedFonts;
            return;
        }// end function

        public function get text() : String
        {
            return this._text;
        }// end function

        public function set text(param1:String) : void
        {
            if (this._text != param1)
            {
                this._text = param1 || "";
                this.changeContent();
                sendEvent(Event.CHANGE);
            }
            return;
        }// end function

        protected function changeText() : void
        {
            this._textField.defaultTextFormat = this._format;
            this.changeContent();
            return;
        }// end function

        protected function changeContent() : void
        {
            if (this._isHtml)
            {
                this._textField.htmlText = this._text;
            }
            else
            {
                this._textField.text = this._text;
            }
            return;
        }// end function

        override protected function changeSize() : void
        {
            if (!isNaN(_width))
            {
                this._textField.autoSize = TextFieldAutoSize.NONE;
                this._textField.width = _width - this._margin[0] - this._margin[2];
                if (isNaN(_height) && this.wordWrap)
                {
                    this._textField.autoSize = TextFieldAutoSize.LEFT;
                }
                else
                {
                    _height = isNaN(_height) ? (18) : (_height);
                    this._textField.height = _height - this._margin[1] - this._margin[3];
                }
            }
            else
            {
                var _loc_1:* = NaN;
                _height = NaN;
                _width = _loc_1;
                this._textField.autoSize = TextFieldAutoSize.LEFT;
            }
            super.changeSize();
            return;
        }// end function

        public function get isHtml() : Boolean
        {
            return this._isHtml;
        }// end function

        public function set isHtml(param1:Boolean) : void
        {
            if (this._isHtml != param1)
            {
                this._isHtml = param1;
                callLater(this.changeText);
            }
            return;
        }// end function

        public function get stroke() : String
        {
            return this._stroke;
        }// end function

        public function set stroke(param1:String) : void
        {
            var _loc_2:Array = null;
            if (this._stroke != param1)
            {
                this._stroke = param1;
                ObjectUtils.clearFilter(this._textField, GlowFilter);
                if (Boolean(this._stroke))
                {
                    _loc_2 = Styles.labelStroke;
                    ObjectUtils.addFilter(this._textField, new GlowFilter(_loc_2[0], _loc_2[1], _loc_2[2], _loc_2[3], _loc_2[4], _loc_2[5]));
                }
            }
            return;
        }// end function

        public function get multiline() : Boolean
        {
            return this._textField.multiline;
        }// end function

        public function set multiline(param1:Boolean) : void
        {
            this._textField.multiline = param1;
            return;
        }// end function

        public function get asPassword() : Boolean
        {
            return this._textField.displayAsPassword;
        }// end function

        public function set asPassword(param1:Boolean) : void
        {
            this._textField.displayAsPassword = param1;
            return;
        }// end function

        public function get autoSize() : String
        {
            return this._textField.autoSize;
        }// end function

        public function set autoSize(param1:String) : void
        {
            this._textField.autoSize = param1;
            return;
        }// end function

        public function get wordWrap() : Boolean
        {
            return this._textField.wordWrap;
        }// end function

        public function set wordWrap(param1:Boolean) : void
        {
            this._textField.wordWrap = param1;
            return;
        }// end function

        public function get selectable() : Boolean
        {
            return this._textField.selectable;
        }// end function

        public function set selectable(param1:Boolean) : void
        {
            this._textField.selectable = param1;
            mouseEnabled = param1;
            return;
        }// end function

        public function get background() : Boolean
        {
            return this._textField.background;
        }// end function

        public function set background(param1:Boolean) : void
        {
            this._textField.background = param1;
            return;
        }// end function

        public function get backgroundColor() : uint
        {
            return this._textField.backgroundColor;
        }// end function

        public function set backgroundColor(param1:uint) : void
        {
            this._textField.backgroundColor = param1;
            return;
        }// end function

        public function get color() : Object
        {
            return this._format.color;
        }// end function

        public function set color(param1:Object) : void
        {
            this._format.color = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get font() : String
        {
            return this._format.font;
        }// end function

        public function set font(param1:String) : void
        {
            this._format.font = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get align() : String
        {
            return this._format.align;
        }// end function

        public function set align(param1:String) : void
        {
            this._format.align = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get bold() : Object
        {
            return this._format.bold;
        }// end function

        public function set bold(param1:Object) : void
        {
            this._format.bold = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get leading() : Object
        {
            return this._format.leading;
        }// end function

        public function set leading(param1:Object) : void
        {
            this._format.leading = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get indent() : Object
        {
            return this._format.indent;
        }// end function

        public function set indent(param1:Object) : void
        {
            this._format.indent = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get size() : Object
        {
            return this._format.size;
        }// end function

        public function set size(param1:Object) : void
        {
            this._format.size = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get underline() : Object
        {
            return this._format.underline;
        }// end function

        public function set underline(param1:Object) : void
        {
            this._format.underline = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get letterSpacing() : Object
        {
            return this._format.letterSpacing;
        }// end function

        public function set letterSpacing(param1:Object) : void
        {
            this._format.letterSpacing = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get margin() : String
        {
            return this._margin.join(",");
        }// end function

        public function set margin(param1:String) : void
        {
            this._margin = StringUtils.fillArrayByString(this._margin, param1, int);
            this._textField.x = this._margin[0];
            this._textField.y = this._margin[1];
            callLater(this.changeSize);
            return;
        }// end function

        public function get embedFonts() : Boolean
        {
            return this._textField.embedFonts;
        }// end function

        public function set embedFonts(param1:Boolean) : void
        {
            this._textField.embedFonts = param1;
            return;
        }// end function

        public function get format() : TextFormat
        {
            return this._format;
        }// end function

        public function set format(param1:TextFormat) : void
        {
            this._format = param1;
            callLater(this.changeText);
            return;
        }// end function

        public function get textField() : TextField
        {
            return this._textField;
        }// end function

        public function appendText(param1:String) : void
        {
            this.text = this.text + param1;
            return;
        }// end function

        public function get skin() : String
        {
            return this._skin;
        }// end function

        public function set skin(param1:String) : void
        {
            return;
        }// end function

        override public function commitMeasure() : void
        {
            exeCallLater(this.changeText);
            exeCallLater(this.changeSize);
            return;
        }// end function

        override public function get width() : Number
        {
            if (!isNaN(_width) || Boolean(this._skin) || Boolean(this._text))
            {
                return super.width;
            }
            return 0;
        }// end function

        override public function set width(param1:Number) : void
        {
            _contentWidth = param1;
            super.width = param1;
            return;
        }// end function

        override public function get height() : Number
        {
            if (!isNaN(_height) || Boolean(this._skin) || Boolean(this._text))
            {
                return super.height;
            }
            return 0;
        }// end function

        override public function set height(param1:Number) : void
        {
            _contentHeight = param1;
            super.height = param1;
            return;
        }// end function

        override public function set dataSource(param1:Object) : void
        {
            _dataSource = param1;
            if (param1 is Number || param1 is String)
            {
                this.text = String(param1);
            }
            else
            {
                super.dataSource = param1;
            }
            return;
        }// end function

    }
}
